package inits

import (
	"github.com/go-playground/validator/v10"
	"regexp"
)

// customValidate 增加validator 验证手机是否合规
func customValidate(fl validator.FieldLevel) bool {
	phone := fl.Field().String()
	pattern := `^1[3-9]\d{9}$`
	matched, _ := regexp.MatchString(pattern, phone)
	return matched
}

// NewValidator 初始化验证器
func NewValidator() *validator.Validate {
	validate := validator.New()
	validate.RegisterValidation("customValidate", customValidate)
	return validate
}
